//
// Created by dave on 18-7-29.
//

#pragma once

#include <string>
#include <vector>
#include "../msg_body.h"
#include "../data_utils.h"
#include <boost/date_time.hpp>

class location_report : public msg_body {
public:
    void decode(std::vector<unsigned char> data, std::size_t start, std::size_t stop) override {
        alarm = read_dword(data, start);
        flag = read_dword(data, start + 4);
        located = (flag & 2) > 0;
        lat = read_dword(data, start + 8) / 1000000.0;
        lng = read_dword(data, start + 12) / 1000000.0;
        height = read_word(data, start + 16);
        speed = read_word(data, start + 18);
        direction = read_word(data, start + 20);
        time = read_bcd(data, start + 22, 6);
    }

    unsigned get_alarm() { return alarm; }
    void set_alarm(unsigned alarm) { this->alarm = alarm; }
    unsigned get_flag() { return flag; }
    void set_flag(unsigned flag) { this->flag = flag; }
    bool is_located() const { return located; }
    void set_located(bool located) { location_report::located = located; }
    double get_lat() { return lat; }
    void set_lat(double lat) { this->lat = lat; }
    double get_lng() { return lng; }
    void set_lng(double lng) { this->lng = lng; }
    int get_height() { return height; }
    void set_height(int height) { this->height = height; }
    int get_speed() { return speed; }
    void set_speed(int speed) { this->speed = speed; }
    int get_direction() { return direction; }
    void set_direction(int direction) { this->direction = direction; }
    std::string get_time() { return time; }
    void set_time(std::string time) { this->time = time; }

private:
    unsigned alarm;
    unsigned flag;
    bool located;
    double lat;
    double lng;
    int height;
    int speed;
    int direction;
    std::string time;
};